home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
telecomm
/
sticpsrc.lzh
/
SOURCE.ARC
/
NRCMD.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-05-10
|
24KB
|
1,076 lines
/* NET/ROM user command processing */
#include <stdio.h>
#include "global.h"
#include "mbuf.h"
#include "ax25.h"
#include "timer.h"
#include "netrom.h"
#include "iface.h"
#include "lapb.h"
#include "cmdparse.h"
#include <ctype.h>
static int dointerface(),dobcnodes(),donodetimer(),donrnodes(),donrroute(),
donrrts(),doobsotimer(),doparam(),donodefilter(),donrstat(),dotcpip(),
donrexclude(),donrinfo(),donrusers();
static struct cmds nrcmds[] = {
"bcnodes", dobcnodes, 2, "<interface>", NULLCHAR,
"exclude", donrexclude, 0, NULLCHAR, NULLCHAR,
"info", donrinfo, 0, NULLCHAR, NULLCHAR,
"interface", dointerface, 4,
"<interface> <alias> <quality> [lap|uplink]",NULLCHAR,
"nodefilter", donodefilter, 0, NULLCHAR, NULLCHAR,
"nodes", donrnodes, 0, NULLCHAR, NULLCHAR,
"nodetimer", donodetimer, 0, NULLCHAR, NULLCHAR,
"obsotimer", doobsotimer, 0, NULLCHAR, NULLCHAR,
"param", doparam, 2, "3|4 <params>", NULLCHAR,
"route", donrroute, 0, NULLCHAR, NULLCHAR,
"routes", donrrts, 0, NULLCHAR, NULLCHAR,
#ifdef NETROM4
"status", donrstat, 0, NULLCHAR, NULLCHAR,
#endif
"tcpip", dotcpip, 0, NULLCHAR,
"normal|link|broadcast|ignore [alias]",
#ifdef NETROM4
"users", donrusers, 0, NULLCHAR, NULLCHAR,
#endif
NULLCHAR, NULLFP, 0,
"?subcommands",
NULLCHAR
};
char nr_savename[80] = ""; /* filename for route save */
char nr_infname[80] = ""; /* filename for INFO output */
#ifdef NETROM4
struct interface *nr_lap = NULLIF; /* Local Access Point interface */
#endif
struct timer nodetimer; /* timer for nodes broadcasts */
static struct timer obsotimer; /* timer for aging routes */
static char nonetrom[] = "Interface \"%s\" not for NET/ROM\n";
static char baddest[] = "Bad destination callsign\n";
static char badneigh[] = "Bad neighbor callsign\n";
static char cr[] = "\r";
/* Command multiplexer */
donetrom(argc,argv)
int argc;
char *argv[];
{
return subcmd(nrcmds,argc,argv);
}
static int dorouteadd(),doroutedrop(),dorouteinfo(),doroutesave();
static struct cmds routecmds[] = {
"add", dorouteadd, 7,
"<dest> <alias> <quality> <obso> <interface> <neighbor>",
"add failed",
"drop", doroutedrop, 4,
"<destination>|* <interface> <neighbor>",
"drop failed",
"info", dorouteinfo, 2,
"<destination>",NULLCHAR,
"save", doroutesave, 0,
"[<filename>]",NULLCHAR,
NULLCHAR, NULLFP, 0,
"?subcommands",
NULLCHAR
};
/* Route command multiplexer */
static
donrroute(argc,argv)
int argc;
char *argv[];
{
if (argc < 2) {
doroutedump(NULLBUFP,0,1);
return 0;
}
return subcmd(routecmds,argc,argv);
}
/* format alias:call in a static buffer */
char *
nr_fmtcall (rp)
struct nrroute_tab *rp;
{
static char buf[20];
char *cp;
strcpy(buf,rp->alias);
/* remove trailing spaces */
if ((cp = index(buf,' ')) == NULLCHAR)
cp = &buf[strlen(buf)];
if (cp != buf) /* don't include colon for null alias */
*cp++ = ':';
pax25(cp,&rp->call);
return buf;
}
/* find out if an active crosslink exists to some neigbor */
/* return it's axp, or NULLAX25 */
static struct ax25_cb *
nrcrosslink (np)
struct nrnbr_tab *np;
{
struct ax25_cb *find_ax25();
struct ax25_addr neighbor,*nr_scall();
getaxaddr(&neighbor,np->call);
return find_ax25(&neighbor,nr_scall(np->interface));
}
/* Dump a list of known routes */
/* also called from the NODES command of NET/ROM level 7 */
doroutedump(bpp,hide,ext)
struct mbuf **bpp; /* append to mbuf if non-NULL */
int hide; /* hide #ALIAS nodes */
int ext; /* extended listing (includes route) */
{
register struct nrroute_tab *rp,*srp;
struct nrroute_tab *sortp = NULLNRRTAB;
struct nrroute_tab **prev;
int i,j;
char line[80],buf[20],tmp[10];
if(ext){ /* put header above extended listing */
strcpy(line,"Call Alias Routing Interf Call Alias Routing Interf");
if(bpp != NULLBUFP){
strcat(line,cr);
append(bpp,qstring(line));
} else
printf("%s\n",line);
}
line[0] = '\0';
/* first pass: every route is put in a sorted list */
for (i = 0; i < NRNUMCHAINS; i++)
for (rp = nrroute_tab[i]; rp != NULLNRRTAB; rp = rp->next) {
if(hide && rp->alias[0] == '#')
continue; /* ignore #ALIAS nodes */
/* insert this one in the list at the proper position */
for (srp = sortp,prev = &sortp; srp != NULLNRRTAB;
prev = &srp->sort, srp = srp->sort){
/* compare srp->call and rp->call */
for (j = 0; j < ALEN; j++)
if (srp->call.call[j] != rp->call.call[j])
break;
if (j < ALEN){
if (uchar(srp->call.call[j]) > uchar(rp->call.call[j]))
break;
} else {
if ((srp->call.ssid & SSID) > (rp->call.ssid & SSID))
break;
}
}
rp->sort = srp;
*prev = rp;
}
/* second pass: the routes are printed in sorted list order */
for (rp = sortp; rp != NULLNRRTAB; rp = rp->sort) {
if(!ext){
sprintf(line + strlen(line),"%-16s ",nr_fmtcall(rp));
} else {
pax25(tmp,&rp->call);
sprintf(line + strlen(line),"%-10s%-7s",tmp,rp->alias);
if (rp->routes == NULLNRBIND){
sprintf(line + strlen(line),"%-22s","no route");
} else {
if(addreq(&rp->call,rp->routes->via->call)){
strcpy(buf,"direct");
} else {
pax25(tmp,rp->routes->via->call);
sprintf(buf,"via %-9s",tmp);
}
sprintf(line + strlen(line),"%-13s %-8s",
buf,rp->routes->via->interface->name);
}
}
if (strlen(line) > 65) {
if(bpp != NULLBUFP){
strcat(line,cr);
append(bpp,qstring(line));
} else
printf("%s\n",line);
line[0] = '\0';
}
}
if (line[0])
if(bpp != NULLBUFP){
strcat(line,cr);
append(bpp,qstring(line));
} else
printf("%s\n",line);
return 0;
}
/* print detailed information on an individual route */
static
dorouteinfo(argc,argv)
int argc;
char *argv[];
{
register struct nrroute_tab *rp;
struct ax25_addr dest;
if (setcall(&dest,argv[1]) < 0) {
printf(baddest);
return -1;
}
if ((rp = find_nrroute(&dest)) == NULLNRRTAB) {
printf("no such route\n");
return -1;
}
printf("CP Qual Obso Interf Neighbor Node: ");
nrrouteinfo(NULLBUFP,rp);
return 0;
}
/* show route info for some callsign */
/* also called from the NODES command of NET/ROM level 7 */
nrrouteinfo (bpp,rp)
struct mbuf **bpp; /* append to this mbuf if non-null */
register struct nrroute_tab *rp;
{
register struct nr_bind *bp;
register struct nrnbr_tab *np;
char neighbor[60];
char line[80];
strcpy(line,nr_fmtcall(rp));
if(bpp != NULLBUFP){
strcat(line,cr);
append(bpp,qstring(line));
} else
printf("%s\n",line);
for (bp = rp->routes; bp != NULLNRBIND; bp = bp->next) {
np = bp->via;
psax25(neighbor,np->call);
sprintf(line,"%c%c %3d %3d %-6s %s",
(nrcrosslink(np) != NULLAX25 ? '>' : ' '),
(bp->flags & NRB_PERMANENT ? 'P' : ' '),
bp->quality,bp->obsocnt,
np->interface->name,
neighbor);
if(bpp != NULLBUFP){
strcat(line,cr);
append(bpp,qstring(line));
} else
printf("%s\n",line);
}
}
/* show routes to NET/ROM neighbors */
/* also called from the ROUTES command of NET/ROM level 7 */
nrrtsdump (bpp)
struct mbuf **bpp; /* append to this mbuf if non-null */
{
struct nrnbr_tab *np;
int i;
char tmp[60];
char line[80];
for (i = 0; i < NRNUMCHAINS; i++)
for (np = nrnbr_tab[i]; np != NULLNTAB; np = np->next){
psax25(tmp,np->call);
sprintf(line,"%c %-6s %3d %3d %-9s",
(nrcrosslink(np) != NULLAX25 ? '>' : ' '),
np->interface->name,
np->interface->nriface->quality,
np->refcnt,tmp);
if (np->failcnt != 0) {
sprintf(tmp," (%d link failure%s)",
np->failcnt,(np->failcnt != 1)? "s":"");
strcat(line,tmp);
}
if(bpp != NULLBUFP){
strcat(line,cr);
append(bpp,qstring(line));
} else
printf("%s\n",line);
}
}
/* set filename for INFO output */
static
donrinfo(argc,argv)
int argc;
char *argv[];
{
if (argc < 2)